xlv.imp.editor={
	implement:function(){
	},
	pub:{
		policy:{install:'replace',offsetLeft:0,offsetTop:0,align:'left',dispose:'dispose',uninstall:'remove'}
			//replace,viewer,attach,none; left,right,middle,center
	},
	method:{
		editor_properties:{
			commitKeyCode:13,
			cancelKeyCode:27,
			notifyExit:[],
			editing:false,
			originalValue:null,
			commitDocumentMouseDown:true
		},
		_editor_keydown:function(event){
			var p=this.editor_properties;
			var src=(event.srcElement||event.target);
			var c=(event.keyCode||event.which);
			this.editor_properties.editing=true;
			switch(c){
				//case Event.KEY_TAB:	
				case p.commitKeyCode:
					event.stop();
					this._editor_endEdit(true);
					break;
				case p.cancelKeyCode:
					event.stop();
				 	this._editor_endEdit(false);
					break;	
			}
		},
		editor_policy:function(){
			return xlv.imp.editor.pub.policy;
		},
		_editor_notifyExit:function(commit){
			var f=this.editor_properties.notifyExit;
			for(var i=0,n=f.length;i<n;++i)	f[i](commit?true:false);
		},
		editor_addExitListener:function(func){
			this.editor_properties.notifyExit.push(func);
		},
		editor_clearExitListener:function(){
			this.editor_properties.notifyExit=[];
		},
		editor_getEditor:function(){
			return (this.$V.editor)?this.$V.editor:this;
		},
		editor_styleFor:function(editor,policy){
			if(policy&&policy.install=='replace'){
				this.editor_getEditor().style.width=policy.inset.width+'px';
			}
		},
		editor_valueToEditor:function(value){
			this.editor_properties.originalValue=value;
		},
		editor_valueFromEditor:function(){
		},
		_editor_startEdit:function(policy){
			if(!this.editor_properties.editing){
				if(xlv.sys.getCurrentEditor()!=this)xlv.sys.stopCurrentEditor(true);
				this.editor_properties.editing=true;
				var editor=this.editor_getEditor();
				this.addEventHandler('mousedown','_editor_document_mousedown',document);
				this.addEventHandler('keydown','_editor_keydown',editor);
				this.editor_styleFor(editor,policy);
				this.editor_focus();
				this.editor_startEdit(policy);
				xlv.sys._registerCurrentEditor(this);
			}
		},
		_editor_document_mousedown:function(event){
			if(!xlv.util.isDescendantOf(event.target,this)){
				if(!xlv.util.isTag(this.editor_getEditor(),'input'))this._editor_endEdit(this.editor_properties.commitDocumentMouseDown);
			}
		},
		editor_focus:function(){
			this.editor_getEditor().focus();
		},
		editor_blur:function(){
			this.editor_getEditor().blur();
		},
		editor_startEdit:function(){
		},
		_editor_endEdit:function(commit){
			if(this.editor_properties.editing){
				commit &= this.editor_validate();
				this.removeObserve('mousedown','_editor_document_mousedown',document);
				this.removeObserve('keydown','_editor_keydown',this.editor_getEditor());
				this.editor_endEdit(commit);
				this._editor_notifyExit(commit);
				this.editor_properties.editing=false;
				this.editor_blur();
				xlv.sys._registerCurrentEditor(null);
			}
		},
		editor_endEdit:function(commit){
		},
		editor_editing:function(){
			return this.editor_properties.editing;
		},
		editor_validate:function(){
			return true;
		},
		editor_dispose:function(){
		}
	}
};

